package model.expression.command;

import model.parser.ParserException;
import state.TabState;
import state.TurtleState;

public class Towards extends AbstractCommandExpression {

	public Towards(TabState ts) {
		super(ts);
	}

	@Override
	protected int getExpNumChildren() {
		return 2;
	}

	@Override
	public int evaluate() {
		if (this.children.size()<2)
			throw ParserException.BAD_ARGUMENTS;
		int newX = (int) this.children.get(0).evaluate();
		int newY = (int) this.children.get(1).evaluate();
		
		TurtleState firstActiveTurtle = tabSt.turtlesMap.get(tabSt.getActiveTurtle().get(0));
		return firstActiveTurtle.towardPoint(newX, newY);
	}
}
